/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.awt.AWTException;
import java.awt.Component;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import model.Plant;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import simulator.GameInit;
import simulator.GraphicalUI;
import simulator.PlantController;

public class GUITestBase {
    public GameInit gin;
    public Plant plant;
    public PlantController presenter;
    public GraphicalUI gui;
    public Robot rob;
    private final int DELAYMS = 200;
    
    @Before
    public void setUp() throws AWTException {
        gin = new GameInit(true);
        presenter = gin.getController();
        gui = gin.getGraphicalUI();
        plant = presenter.getPlant();
        rob = new Robot();
    }
    
    @After
    public void tearDown() {
        gui.dispose();
    }
    
    protected Robot getRobot() {
        return rob;
    }
    
    // <3 method overloading - good luck w/ debugging -> tnx Java
    public void pressMouse(Component comp) {
        pressMouse(comp.getLocationOnScreen());
    }
    
    public void pressMouse(Point p) {
        pressMouse(p, 2);
    }
    
    public void pressMouse(Point p, int offset) {
        pressMouse(p.x + offset, p.y + offset);
    }
    
    public void pressMouse(int x, int y) {
        getRobot().delay(DELAYMS);
        getRobot().mouseMove(x, y);
        getRobot().mousePress(InputEvent.BUTTON1_DOWN_MASK);
        getRobot().mouseRelease(InputEvent.BUTTON1_MASK);
        getRobot().delay(DELAYMS);
    }

    public void keyPress(int key) {
        getRobot().delay(DELAYMS);
        getRobot().keyPress(key);
        getRobot().keyRelease(key);
        getRobot().delay(DELAYMS);
    }
}
